<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<c-rt:set var="frontContextPath" value='<%=ServerValue.getFrontContextPath()%>'/>
<html>
<head>
<script language="javascript">
	$().ready(function(){
		
		$("#read_dialog").dialog({
			bgiframe: true,
			autoOpen: false,
			width:300,
			modal: true
		});

		$("#recheck_dialog").dialog({
			bgiframe: true,
			autoOpen: false,
			width:350,
			modal: true
		});
		
		$("#iv").attr("src","${frontContextPath}/servlet/imageValid.jpg?"+Math.random());

		$("#chang_image").click(function(){
			$("#iv").attr("src","${frontContextPath}/servlet/imageValid.jpg?"+Math.random());
		});
		
		$("#radio1").click(function(){
			$("span:[id*=Tip]").html('');
			$("#tab1").attr('class','stab-fo');
			$("#tab2").attr('class','stab');
			$(".ul-list label").eq(1).text('密码：');
			$("#first1").hide();
			$("#first2").hide();
			$("#first3").hide();
			$("#ever1").show();
			$("#pwd").val('');
			<c:if test="${errTimes<=3}">$("#ever2").hide();</c:if>
		});
		
		$("#login").click(function(){
			var isCorrect = true;
			var isFirst = $('input[name=isFirst]:checked').val();
			$("span:[id*=Tip]").html('');

			$("#mail").val(jQuery.trim($("#mail").val()).toLowerCase());
			if($("#mail").val()==''){
				$("#mailTip").html('<span class="msg rn">请输入联络邮箱</span>');
				isCorrect = false;
			}else if($("#mail").val().match(/.+@.+\..+/)==null || $("#mail").val().indexOf(' ')>=0 || chineseCount($("#mail").val())>0){
				$("#mailTip").html('<span class="msg rn">邮箱格式不正确</span>');
				isCorrect = false;
			}

			var text = $("#pwd").val();
			if(text.length==0){
				$("#pwdTip").html('<span class="msg rn">请输入密码</span>');
				isCorrect = false;
			}else if(isFirst==2){
				if(text.length<6||text.length>16){
					$("#pwdTip").html('<span class="msg rn">密码长度只能在6-16位字符之间</span>');
					isCorrect = false;
				}else if(text.indexOf(' ')>=0){
					$("#pwdTip").html('<span class="msg rn">密码不能含有空白</span>');
					isCorrect = false;
				}else if(text.match(/[^a-zA-Z0-9]/g)){
					$("#pwdTip").html('<span class="msg rn">只能使用大小写英文字母、数字</span>');
					isCorrect = false;
				}
			}

			if(isFirst==2&&$("#rcpwd").val()!=text){
				$("#rcpwdTip").html('<span class="msg rn" id="rcpwdTip">两次密码不同</span>');
				isCorrect = false;
			}

			if(((${errTimes}>3 && isFirst==1) || isFirst==2 ) && $("#ccode").val() == ""){
				$("#ccodeTip").html('<span class="msg rn">请输入验证码</span>');
				isCorrect = false;
			}

			if(isCorrect){
				if(isFirst==2){
					if($("#is_read").attr('checked')){
						$.post("${frontContextPath}/nonMember/checkEmail.do",{mail:$("#mail").val(),ccode:$("#ccode").val()},checkResult,"json");
					}else{
						$("#read_dialog").dialog('open');
					}
					return false;
				}
				$("#memberForm").submit();
			}
			return false;
		});

		<c:if test="${isFirst != 2}">$("#radio1").click();</c:if>
		<c:if test="${isFirst eq 2}">$("#radio2").click();</c:if>

		$("#read_dialog_commit").click(function(){
			$("#read_dialog").dialog('close');
		});

		$("#cancel").click(function(){
			$("#recheck_dialog").dialog('close');
		});

		$("#submit").click(function(){
			$("#memberForm").submit();
			return false;
		});

		$("#nomember-order").show();
		if("${result}" == "code_error"){
			$("#ccodeTip").html('<span class="msg rn">验证码错误，请重新输入</span>');
		}else if("${result}" == "mail_exist"){
			$("#mailTip").html('<span class="msg rn">您可能曾经使用此邮箱注册过，您可以<a href="javascript:;" onclick="login();return false;">登录</a>或用设定其他邮箱</span></span>');
		}else if("${result}" == "unfind"){
			$("#mailTip").html('<span class="msg rn">帐号不存在</span>');
		}else if("${result}" == "ismember"){
			$("#mailTip").html('<span class="msg rn">会员请<a href="${frontContextPath}/tologin.do">点此</a>登录</span>');
		}else if("${result}" == "pwd_error"){
			$("#pwdTip").html('<span class="msg rn">请输入正确密码</span>');
		}else if("${result}" == "isregmember"){
			$("#mailTip").html('<span class="msg rn">您可能曾经使用此邮箱注册过，您可以<a href="${frontContextPath}/tologin.do">登录</a>或用设定其他邮箱</span>');
		}
	});
	
	function chineseCount(word){
	    var length=0;
	    for(var cc=0;cc<word.length;cc++){
	       var c = word.charCodeAt(cc);
	      if (!(c>=32&&c<=126)) length++;
	    }
	    return length;
	}

	function login(){$("#radio1").click();}

	function checkResult(result){
		if(result=='ok'){
			$("#rcmail").html($("#mail").val());
			$("#recheck_dialog").dialog('open');
			return false;
		}else if(result == "mail_exist"){
			$("#mailTip").html('<span class="msg rn">您可能曾经使用此邮箱注册过，您可以<a href="javascript:;" onclick="login();return false;">登录</a>或用设定其他邮箱</span></span>');
		}else if(result == "isregmember"){
			$("#mailTip").html('<span class="msg rn">您可能曾经使用此邮箱注册过，您可以<a href="${frontContextPath}/tologin.do">登录</a>或用设定其他邮箱</span>');
		}else if(result == "code_error"){
			$("#ccodeTip").html('<span class="msg rn">验证码错误，请重新输入</span>');
		}
		$("#pwd").val('');
		$("#rcpwd").val('');
		$("#ccode").val('');
		$("#chang_image").click();
	}
</script>
</head>
<body>
<%
String from = "yaodian100";
if(request.getCookies()!=null) {
for(Cookie c:request.getCookies()) {
	if("_from".equals(c.getName())) {
		from = c.getValue();
	}
}}

if("taobao".equals(from) || "taobao".equals(request.getAttribute("_from"))) {
%>
<script>
window.location.href='http://login.taobao.com/member/login.jhtml?f=top&redirectURL=http%3A%2F%2Fcontainer.api.taobao.com%2Fcontainer%3Fappkey%3D12156713%26redirectURL%3Dhttp%253A%252F%252Fwww.yaodian100.com%252Fecmall%252Ftologin.do%253Fredirect_url%253Dhttp%25253A%25252F%25252Fwww.yaodian100.com%25252Fecmall%25252Fmember%25252Fmyyaodian.do%25253Fhpp%25253DItpbar_1';
</script>
<% } %>
<div id="main" class="member-reg">
  	<h3>非会员购买</h3>
  	<div id="nomember-order" style="display:none;">
      
        <s:form action="login.do" method="post" id="memberForm">
        <p class="stab-area" style="display:none;">
        	<label class="stab-fo" id="tab1">
                <input type="radio" name="isFirst" id="radio1" value="1" checked="checked" />
        		已经设过邮箱/密码</label>
        </p>
        
        <ul class="ul-list">
           <li><div><label>您的联络邮箱：</label></div><div><input size="20" value="${mail}" id="mail" name="mail" maxlength="100"/><span style="display:block" id="mailTip"></span></div></li>
           <li><div><label>密码：</label></div><div><input type="password" size="20" name="pwd" id="pwd" maxlength="16"/> <a href="${frontContextPath}/goforgrtpwdemail.do" id="ever1">忘记密码</a> <span style="display:block" id="pwdTip"></span></div></li>
           <li id="ever2"><div><label>验证码：</label></div><div><input type="text" class="ipt-w20" name="ccode" id="ccode" maxlength="10"/>
      	   <img id="iv" name="iv"> <a href="javascript:;" id="chang_image">看不清？换张图</a><span style="display:block" id="ccodeTip"></span>
      	   <br /></div></li>
        </ul>
        <input type="hidden" name="errTimes" value='${errTimes}' />
        <input type="hidden" name="redirect_url" value='${redirect_url}' />
        </s:form>        
      	<br />
        <p align="center"><a class="btn-mid" href="javascript:;" id="login">确认</a></p>
    </div>
  </div>
<div id="read_dialog" title="请勾选并同意交易条款" class="alert-1" style="display:none">
         <p>请勾选并同意《交易条款》</p>
         <div align="center"><span style="text-align:center;"><a href="javascript:;" class="btn-mid" id="read_dialog_commit">确定</a></span></div>
</div>
<div id="recheck_dialog" title="请确认邮箱是否正确" class="alert-caution" style="display:none">
         <p>您的联络邮箱为<span class="txt-rd" id="rcmail"></span><br />
           您将透过此邮箱收到订单进度通知邮件，<br />
         设定后无法修改，请确认您的邮箱是否正确</p>
         <div align="center"><a href="javascript:;" class="btn-mid" onfocus="blur()" id="submit">确定</a> <a href="javascript:;" class="btn-mid" onfocus="blur()" id="cancel">修改</a></div>
</div>
</body>
</html>